<template>
	<view>
		<view class="bannerBox">
			<image src="https://ys.luowangtech.club/static/public/img/a.jpg" mode=""></image>
		</view>
		<view class="content">
			<form @submit="formSubmit">
				<input type="text" placeholder="姓名" name="name" />
				<input type="number" placeholder="输入手机号(方便我们联系您)" name="mobile" />
				<view class="agreement">
					<checkbox-group @change="checkboxChange">
						<label>
							<checkbox value="1" color="#f4984b" />
						</label>
					</checkbox-group>
					<view class="left">阅读并同意<text @click="openAgreement">《月嫂入驻协议》</text></view>
				</view>
				<button form-type="submit">提交申请</button>
			</form>
		</view>
	</view>
</template>

<script>
	import {dns} from '@/pages/dns.js'
	export default {
		data(){
			return{
				checkBoxVal: null
			}
		},
		watch:{
			checkBoxVal(newval,oldval){
				console.log(newval,oldval)
			}
		},
		methods:{
			checkboxChange(e){
				console.log(e);
				this.checkBoxVal = e.detail.value[0];
			},
			formSubmit(e){
				var name = e.detail.value.name;
				var mobile = e.detail.value.mobile;
				var token = uni.getStorageSync('token');
				if(token==''){
					uni.showModal({
					    title: '提示',
					    content: '当前游客状态，请登录',
					    success: function (res) {
					        if (res.confirm) {
					            uni.navigateTo({
					            	url: '/pages/index/login/index'
					            })
					        }
					    }
					});
					return
				}
				if(name==''||mobile==''){
					uni.showToast({
						icon: 'none',
					    title: '请输入正确的姓名和手机号!',
					    duration: 1500
					});
					return
				}
				if(this.checkBoxVal !== '1'){
					uni.showToast({
						icon: 'none',
					    title: '请阅读并同意《小時候家政中心服务协议》!',
					    duration: 1500
					});
					return
				}
				uni.request({
					method: 'POST',
					header: {
						token: token
					},
					data: {
						name: name,
						mobile: mobile
					},
					url: dns + 'matron/apply',
					success: (res)=>{
						console.log(res)
						var msg = res.data.msg;
						if(res.data.status == -1){
							uni.showToast({
								icon: 'none',
							    title: msg,
							})
							return;
						}
						if(res.data.status == 0){
							uni.showToast({
								icon: 'none',
							    title: msg,
							})
							return;
						}
						if(res.data.status == 1){
							uni.showToast({
							    title: msg,
							})
							return;
						}
						
					}
				})
			},
			openAgreement(){//打开用户协议
				uni.navigateTo({
					url: './agreement/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	.bannerBox{
		width: 100%;
		height: 250upx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.content{
		padding: 50upx 30upx;
		input{
			width: 100%;
			height: 60upx;
			background-color: #f8f8f8;
			padding-left: 20upx;
			line-height: 60upx;
			font-size: 30upx;
			margin-bottom: 20upx;
			border-radius: 8upx;
		}
		.input-placeholder{
			color: #afafaf
		}
		.agreement{
			display: flex;
			font-size: 30upx;
			checkbox{
				transform:scale(0.7);
			}
			.left{
				line-height: 50upx;
				text{
					color: #f4984b;
					font-size: 24upx;
					margin-left: 16upx;
				}
			}
		}
		button{
			background-color: #f4984b;
			color: #fff;
			margin-top: 50upx;
			font-size: 28upx;
			line-height: 70upx;
		}
	}
</style>
